﻿using System;
using System.Collections.Generic;
using System.Net;

using RexToy.Logging;

namespace RexToy.Cassandra
{
    class RoundRobinPolicy : ILoadBalancePolicy
    {
        private static ILog _log = LogContext.GetLogger<ILoadBalancePolicy>();

        private int index;
        private int size;
        public void Initialize(List<DnsEndPoint> hosts)
        {
            size = hosts.Count;
        }

        public void Pick(Cluster.Context ctx)
        {
            if (ctx.Stop)
                return;

            int selected = index % size;
            index++;

            ctx.SelectedIndex = selected;
        }

        public void Recycle(Cluster.Context ctx)
        {
        }
    }
}
